<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>OOP Javascript</title>
<script type="text/javascript">
	var Human = function(name) {
		this.name = name;
		this.getName = function() {
			return this.name;
		};
	};
	
	var Kim = function(name) {
		this.parent = new Human('Kim');
		this.name = name;
		
		this.getFullName = function() {
			return this.name + ' ' + this.parent.name;
		};
	};
	
	function viewFullName() {
		var name = document.getElementById('firstName').value;
		
		if (name.length === 0) {
			alert('이름을 입력해 주세요.');
		} else {
			var fullName = new Kim(name);
			
			document.getElementById('fullName').innerHTML = fullName.getFullName();
		}
	}
	
</script>
</head>
<body>
	<h1>부모님의 성을 상속받다</h1>
	<div>
		<input type="text" id="firstName" /> 이름을 입력하세요. <br />
		<button type="button" onclick="viewFullName();">전체 이름 보기</button> <br />
		<span id="fullName"></span>
	</div>
</body>
</html>